#!/anaconda3/envs/Script/bin python3.8
# -*- coding: utf-8 -*-
# ---
# @Software: PyCharm
# @File: image_share.py
# @Author: AllenFu
# @Institution: NCHU, China
# @E-mail: nchufujianjian@126.com
# @Site: 
# @Time: 11月 27, 2020
# ---
from sqlalchemy_serializer import SerializerMixin

from app import dBSession
from app.models.base_model import BaseModel
from app.models.model import HtImgShard
from app.vendor.utils import Utils


class ImgShard(HtImgShard, BaseModel, SerializerMixin):

    # 增加分片数据
    @staticmethod
    def add(index, uuid, imgString):
        data = ImgShard(index=index, uuid=uuid, imgString=imgString)
        dBSession.add(data)
        return dBSession.commit()

    # 根据uuid获取分片数据
    @staticmethod
    def getData(uuid):
        obj = dBSession.query(ImgShard).filter_by(uuid=uuid).order_by('index').all()
        data = Utils.db_l_to_d(obj)
        return data